<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="../../js/jQuery/jquery-1.8.3.min.js"></script>
    <script src="../../js/jQuery/jquery.form.js"></script>
    <script type="text/javascript">
       function initData(){
       		var recordId = request("recordId");
       		if(recordId){
       			$.post(top.OB.Application.contextUrl+"./org.openbravo.client.kernel?_action=com.mes.handler.FileManagerGetHandler",
       			{recordId:recordId},
       			function(data){
       				if(data.result){
       					$("#fileName").val(data.data.fileName);
       					$("#fileDesc").val(data.data.fileDesc);
       					//$("#isUse").val(data.data.isUse?"Y":"N");
       					$("input[name='isUse']").removeAttr('checked'); 
       					$("input[name='isUse'][value='"+(data.data.isUse?"Y":"N")+"']").attr("checked",true);
       					$("#version").val(data.data.version);
       				}
       			});
       		}
       }
       initData();
       
       function fmUpload() {
           var fileTypeId = request("fileTypeId");
           var recordId = request("recordId");
           $("#fileTypeId").val(fileTypeId);
           if(recordId){
           		$("#recordId").val(recordId);
           }
           
           if(!recordId){
	          if($("#fileSource").val() == '' &&  $("#fileSource").val() == ''){
	              top.isc.showMessage("请选择上传文件",top.isc.OBMessageBar.TYPE_ERROR);
	              return;
	          }
           }
           recordId = recordId?recordId:"";
           var options = {
                url: top.OB.Application.contextUrl+"./org.openbravo.client.kernel?_action=com.mes.handler.FileManagerSubmitHandler&recordId="+recordId,
                type: 'POST',
                dataType:'json',
                data:{},
                async: false,
                success: function(data){
                    if(data.result){
                    	   top.OB.Emes_ActionButton.FmFileRefresh();
                        top.isc.showMessage(data.desc,top.isc.OBMessageBar.TYPE_SUCCESS);
                        top.OB.Layout.ClassicOBCompatibility.Popup.close("fileManagerUpload");
                    }else{
                        top.isc.showMessage(data.desc,top.isc.OBMessageBar.TYPE_ERROR);
                        top.OB.Layout.ClassicOBCompatibility.Popup.close("fileManagerUpload");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    top.isc.showMessage("上传失败",top.isc.OBMessageBar.TYPE_ERROR);
                },
                beforeSubmit:function(formData, jqForm, options){
                	for(var ii in formData){
                		if(formData[ii].name=='fileTypeId'&&!formData[ii].value){
                			top.isc.showMessage("参数错误！",top.isc.OBMessageBar.TYPE_ERROR);
                			return false;
                		}
                		if(formData[ii].name=='fileName'&&!formData[ii].value){
                			top.isc.showMessage("请填写文件名称！",top.isc.OBMessageBar.TYPE_ERROR);
                			return false;
                		}
                		if(formData[ii].name=='version'&&!formData[ii].value){
                			top.isc.showMessage("请填写版本号！",top.isc.OBMessageBar.TYPE_ERROR);
                			return false;
                		}
                	}
                	return true;
                }
            };
            $("#importFile").ajaxSubmit(options);
            
       }
       
       
       function request(name) {
           var url = window.location.href;
           var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
           var url_paraObj = {}
           for (var i = 0; i < paraString.length; i++) {
               var index = paraString[i].indexOf("=");
               try {
                   url_paraObj[paraString[i].substring(0, index)] = decodeURI(paraString[i].substring(index + 1));
               } catch (e) {
                   url_paraObj[paraString[i].substring(0, index)] = paraString[i].substring(index + 1);
               }
           }
           return url_paraObj[name];
       }
    </script>
</head>
<body>
    <form name="importFile" id="importFile" method="post" enctype="multipart/form-data" align="center">
	    <input type="hidden" name="fileTypeId" id="fileTypeId" value="" />
	    <input type="hidden" name="recordId" id="recordId" value="" />
	    <table cellpadding="5" cellspacing="5">
	    	<tr>
	        	<td align="right" style="width: 180px">文件名称：</td>
	        	<td style=""><input type="text" name="fileName" id="fileName" /></td>
	        </tr>
	        <tr>
	        	<td align="right">版本：</td>
	        	<td><input type="text" name="version" id="version" /></td>
	        </tr>
	        <tr>
	        	<td align="right">备注：</td>
	        	<td><input type="text" name="fileDesc" id="fileDesc" /></td>
	        </tr>
	        <tr>
	        	<td align="right">是否有效：</td>
	        	<td><input type="radio" name="isUse" value="Y" checked="checked"/>是 <input type="radio" name="isUse" value="N" />否</td>
	        </tr>
	        <tr>
	        	<td align="right">文件上传：</td>
	        	<td><input type="file" name="fileSource" id="fileSource" /></td>
	        </tr>
	        <tr>
	         	<td colspan="2"><input type="button" value="提交" style="height: 30px;width: 80px;background-color: #4d7607;color: #fff;" onclick="fmUpload()"/></td>
	        </tr>
	     </table>
    </form>
       
</body>
</html> 
